Simple Substring Search


Exercise 1

Write a function that takes a string and a substring as parameter. It should print true if the substring is found anywhere in the string, false otherwise.

   
  function checkString(str, subStr) {
      if (str.includes(subStr)) {
          console.log(true);
      } else {
          console.log(false);
      }
  }
  

  checkString("hello world", "world"); // Output: true
  checkString("hello world", "planet"); // Output: false
Check Console checkString("hello world", "world");
checkString("hello world", "planet");